//
//  TMGuideViewController.m
//  TMtravel
//
//  Created by Playboy on 2017/3/30.
//  Copyright © 2017年 tmkj. All rights reserved.
//

#import "TMGuideViewController.h"
#import "Masonry.h"
#import "UIImage+MingleChang.h"

@interface TMGuideViewController ()

@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;

@end

@implementation TMGuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self configureView];
}

- (void)configureView {
    self.scrollView.contentSize = CGSizeMake(kScreenWidth * 3, kScreenHeight);
    for (int i = 0; i<3; i++) {
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.contentMode=UIViewContentModeBottom;
        imageView.frame = CGRectMake(i * kScreenWidth, 0, kScreenWidth, kScreenHeight);
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"app_launch_guide%d",i+1]];
        imageView.image=[imageView.image mc_resetToScale:kScreenWidth/imageView.image.size.width];
        imageView.userInteractionEnabled = YES;
        [self.scrollView addSubview:imageView];
        
        if (i == 2) {
            UIButton *startButton = [UIButton buttonWithType:UIButtonTypeCustom];
            [startButton setBackgroundImage:[UIImage imageNamed:@"app_launch_button"] forState:UIControlStateNormal];
            [startButton addTarget:self
                            action:@selector(startButtonClick)
                  forControlEvents:UIControlEventTouchUpInside];
            [imageView addSubview:startButton];
            [startButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.mas_equalTo(-70);
                make.left.mas_equalTo(kScreenWidth/2-90);
            }];
        }
    }
}

- (void)drawLinearGradient:(CGContextRef)context
                      path:(CGPathRef)path
                startColor:(CGColorRef)startColor
                  endColor:(CGColorRef)endColor
{
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGFloat locations[] = { 0.0, 1.0 };
    
    NSArray *colors = @[(__bridge id) startColor, (__bridge id) endColor];
    
    CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colors, locations);
    
    
    CGRect pathRect = CGPathGetBoundingBox(path);
    
    //具体方向可根据需求修改
    CGPoint startPoint = CGPointMake(CGRectGetMinX(pathRect), CGRectGetMidY(pathRect));
    CGPoint endPoint = CGPointMake(CGRectGetMaxX(pathRect), CGRectGetMidY(pathRect));
    
    CGContextSaveGState(context);
    CGContextAddPath(context, path);
    CGContextClip(context);
    CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
    CGContextRestoreGState(context);
    
    CGGradientRelease(gradient);
    CGColorSpaceRelease(colorSpace);
}


- (void)startButtonClick {
    TMTabBarViewController *tabBar = [[TMTabBarViewController alloc] init];
    [TMShareData shareData].tarBarVC = tabBar;
    tabBar.selectedIndex = 0;
    [self presentViewController:tabBar animated:YES completion:nil];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
